package com.cly.config;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(value = SmsProperties.class)
public class SmsAutoConfiguration {

    @Autowired
    private SmsProperties smsProperties;

    /**
     * 发送短信到客户端
     * @return
     */
    @Bean
    public IAcsClient acsClient() throws ClientException {
        IClientProfile profile = DefaultProfile.getProfile(smsProperties.getRegion(),
                smsProperties.getAccessKeyId(),
                smsProperties.getAccessKeySecret()
        );
        DefaultProfile.addEndpoint(smsProperties.getRegion(), smsProperties.getRegion(), smsProperties.getProduct(), smsProperties.getDomain());
        return new DefaultAcsClient(profile);
    }

}
